from ui.fittable_widgets import FittableButton
from kivy.properties import BooleanProperty


class DisableableButton(FittableButton):
    enabled = BooleanProperty(True)

    def __init__(self, **kwargs):
        super(DisableableButton, self).__init__(**kwargs)

    def on_enabled(self, instance, value):
        if self.enabled is True:
            self.opacity = 1
        else:
            self.opacity = 0.5

    def dispatch(self, *args):
        if self.enabled is True:
            super(FittableButton, self).dispatch(*args)
